package com.woniuxy.provider;

import com.woniuxy.entity.Dish;
import com.woniuxy.entity.DishCategory;
import com.woniuxy.entity.Order;
import org.apache.ibatis.jdbc.SQL;

public class DishCategoryProvider {

        public String update(DishCategory dishCategory) {
            return new SQL() {
                {
                    /*双大括号初始化*/
                    UPDATE("gfr_dish_category");
                    if (dishCategory.getDishCategoryName() != null &&
                    dishCategory.getDishCategoryName().length()!= 0) {
                        SET("dish_category_name='" + dishCategory.getDishCategoryName() + "'");
                    }
                    if (dishCategory.getStatus() != null && dishCategory.getStatus().length() != 0) {
                        SET("status='" + dishCategory.getStatus() + "'");
                    }
                    if (dishCategory.getNavable()!= null && dishCategory.getNavable().length() != 0) {
                        SET("navable='" + dishCategory.getNavable() + "'");
                    }
                    WHERE("id=" + dishCategory.getId());
                }
            }.toString();
        }

    public String getByCondition(DishCategory dishCategory) {
        return new SQL() {{
            SELECT("*");
            FROM("gfr_dish_category");
            if (dishCategory != null) {
                if (dishCategory.getDishCategoryName() != null && dishCategory.getDishCategoryName().length() != 0) {
                    WHERE("dishCategoryName ='" +dishCategory.getDishCategoryName() + "'");
                }
                if (dishCategory.getNavable() != null && dishCategory.getNavable().length() != 0) {
                    WHERE("navable ='" + dishCategory.getNavable() + "'");
                }
                if (dishCategory.getStatus() != null && dishCategory.getStatus().length() != 0) {
                    WHERE("status ='" + dishCategory.getStatus() + "'");
                }

            }
        }}.toString();
    }

}
